package org.example.game.history;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/06/30 11:08
 */
public class Solution100357 {

    public static void main(String[] args) {
        System.out.println(new Solution100357().maximumLength(new int[]{4,51,68}));
    }


    public int maximumLength(int[] nums) {

        int[] res = new int[4];

        for (int i = 0; i < nums.length; i++) {
            nums[i] = nums[i] % 2;
            if(i>0){
                if(nums[i-1] == 1 && nums[i] == 1){
                    res[0]++;
                }else if(nums[i-1] == 1 && nums[i] == 0){
                    res[1]++;
                }else if(nums[i-1] == 0 && nums[i] == 1){
                    res[2]++;
                }else if(nums[i-1] == 0 && nums[i] == 0){
                    res[3]++;
                }
            }
        }

        // 11, 12 , 21 ,22
        int max = 1;
        for (int i = 0; i < res.length; i++) {
            max = Math.max(max, res[i]);
        }

        int maxIndex = 0;

        for (int i = 0; i < res.length; i++) {
            if(max == res[i]){
                //  11, 12 , 21 ,22
                int a = 1;
                int b = 1;
                if(i == 0){
                    a = 1;
                    b = 1;
                }else if(i==1){
                    a = 1;
                    b = 0;
                }else if(i==2){
                    a = 0;
                    b = 1;
                }else {
                    a = 0;
                    b = 0;
                }

                int index = 0;
                for (int j = 0; j < nums.length; j++) {
                    if(index%2 == 0 && a == nums[j]){
                        index++;
                    }else if(index%2 == 1 && b == nums[j]){
                        index++;
                    }
                }
                maxIndex = Math.max(index, maxIndex);
            }
        }

        return maxIndex;
    }

}
